update rturk and twilio-ruby, both confirmed to work; improve TwilioAgent documentation

Andrew Cantino 11 years ago
parent
commit
a36078c190
3 changed files with 17 additions and 17 deletions
  1. 2 2
      Gemfile
  2. 5 5
      Gemfile.lock
  3. 10 10
      app/models/agents/twilio_agent.rb

+ 2 - 2
Gemfile

@@ -10,7 +10,7 @@ gem 'bootstrap-kaminari-views', '~> 0.0.2'
10 10
 gem 'rufus-scheduler', '~> 3.0.7', require: false
11 11
 gem 'json', '~> 1.8.1'
12 12
 gem 'jsonpath', '~> 0.5.3'
13
-gem 'twilio-ruby', '~> 3.10.0'
13
+gem 'twilio-ruby', '~> 3.11.5'
14 14
 gem 'ruby-growl', '~> 4.1.0'
15 15
 
16 16
 gem 'delayed_job', '~> 4.0.0'
@@ -40,7 +40,7 @@ gem 'nokogiri', '~> 1.6.1'
40 40
 
41 41
 gem 'wunderground', '~> 1.2.0'
42 42
 gem 'forecast_io', '~> 2.0.0'
43
-gem 'rturk', '~> 2.11.0'
43
+gem 'rturk', '~> 2.12.1'
44 44
 
45 45
 gem 'twitter', '~> 5.7.1'
46 46
 gem 'twitter-stream', github: 'cantino/twitter-stream', branch: 'master'

+ 5 - 5
Gemfile.lock

@@ -215,7 +215,7 @@ GEM
215 215
       rspec-core (~> 2.14.0)
216 216
       rspec-expectations (~> 2.14.0)
217 217
       rspec-mocks (~> 2.14.0)
218
-    rturk (2.11.3)
218
+    rturk (2.12.1)
219 219
       erector
220 220
       nokogiri
221 221
       rest-client
@@ -263,7 +263,7 @@ GEM
263 263
     treetop (1.4.15)
264 264
       polyglot
265 265
       polyglot (>= 0.3.1)
266
-    twilio-ruby (3.10.1)
266
+    twilio-ruby (3.11.5)
267 267
       builder (>= 2.1.2)
268 268
       jwt (>= 0.1.2)
269 269
       multi_json (>= 1.3.0)
@@ -289,7 +289,7 @@ GEM
289 289
       macaddr (~> 1.0)
290 290
     warden (1.2.3)
291 291
       rack (>= 1.0)
292
-    webmock (1.13.0)
292
+    webmock (1.17.4)
293 293
       addressable (>= 2.2.7)
294 294
       crack (>= 0.3.2)
295 295
     weibo_2 (0.1.6)
@@ -337,14 +337,14 @@ DEPENDENCIES
337 337
   rr
338 338
   rspec
339 339
   rspec-rails
340
-  rturk (~> 2.11.0)
340
+  rturk (~> 2.12.1)
341 341
   ruby-growl (~> 4.1.0)
342 342
   rufus-scheduler (~> 3.0.7)
343 343
   sass-rails (~> 4.0.0)
344 344
   select2-rails (~> 3.5.4)
345 345
   shoulda-matchers
346 346
   therubyracer (~> 0.12.1)
347
-  twilio-ruby (~> 3.10.0)
347
+  twilio-ruby (~> 3.11.5)
348 348
   twitter (~> 5.7.1)
349 349
   twitter-stream!
350 350
   typhoeus (~> 0.6.3)

+ 10 - 10
app/models/agents/twilio_agent.rb

@@ -7,17 +7,16 @@ module Agents
7 7
     cannot_create_events!
8 8
 
9 9
     description <<-MD
10
-      The TwilioAgent receives and collects events and sends them via text message or gives you a call when scheduled.
10
+      The TwilioAgent receives and collects events and sends them via text message (up to 160 characters) or gives you a call when scheduled.
11 11
 
12
-      It is assumed that events have a `message`, `text`, or `sms` key, the value of which is sent as the content of the text message/call. You can use Event Formatting Agent if your event does not provide these keys.
12
+      It is assumed that events have a `message`, `text`, or `sms` key, the value of which is sent as the content of the text message/call. You can use the EventFormattingAgent if your event does not provide these keys.
13 13
 
14 14
       Set `receiver_cell` to the number to receive text messages/call and `sender_cell` to the number sending them.
15 15
 
16 16
       `expected_receive_period_in_days` is maximum number of days that you would expect to pass between events being received by this agent.
17 17
 
18
-      If you would like to receive calls, then set `receive_call` to true. `server_url` needs to be 
19
-      filled only if you are making calls. Dont forget to include http/https in `server_url`.
20
-
18
+      If you would like to receive calls, set `receive_call` to `true`. In this case, `server_url` must be set to the URL of your
19
+      Huginn installation (probably "https://#{ENV['DOMAIN']}"), which must be web-accessible.  Be sure to set http/https correctly.
21 20
     MD
22 21
 
23 22
     def default_options
@@ -43,13 +42,14 @@ module Agents
43 42
       @client = Twilio::REST::Client.new options['account_sid'], options['auth_token']
44 43
       memory['pending_calls'] ||= {}
45 44
       incoming_events.each do |event|
46
-        message = (event.payload['message'] || event.payload['text'] || event.payload['sms']).to_s
47
-        if message != ""
45
+        message = (event.payload['message'].presence || event.payload['text'].presence || event.payload['sms'].presence).to_s
46
+        if message.present?
48 47
           if options['receive_call'].to_s == 'true'
49 48
             secret = SecureRandom.hex 3
50 49
             memory['pending_calls'][secret] = message
51 50
             make_call secret
52 51
           end
52
+
53 53
           if options['receive_text'].to_s == 'true'
54 54
             message = message.slice 0..160
55 55
             send_message message
@@ -71,11 +71,11 @@ module Agents
71 71
     def make_call(secret)
72 72
       @client.account.calls.create :from => options['sender_cell'],
73 73
                                    :to => options['receiver_cell'],
74
-                                   :url => post_url(options['server_url'],secret)
74
+                                   :url => post_url(options['server_url'], secret)
75 75
     end
76 76
 
77
-    def post_url(server_url,secret)
78
-      "#{server_url}/users/#{self.user.id}/web_requests/#{self.id}/#{secret}"
77
+    def post_url(server_url, secret)
78
+      "#{server_url}/users/#{user.id}/web_requests/#{id}/#{secret}"
79 79
     end
80 80
 
81 81
     def receive_web_request(params, method, format)